<template>
  <el-form
    :model="state.formData"
    ref="formRef"
    @submit.prevent
    label-width="120px"
  >
    <el-form-item label="请选择导出年份">
      <el-radio-group v-model="state.formData.year">
        <el-radio
          :label="item"
          v-for="item in state.yearList"
          :key="item"
        ></el-radio>
      </el-radio-group>
    </el-form-item>
  </el-form>

  <el-row justify="end">
    <el-button @click="handleCancel">取 消</el-button>
    <el-button type="primary" @click="handleSubmit">确 定</el-button>
  </el-row>
</template>

<script lang="ts" setup>
import { reactive, defineEmits } from "vue";

import { postDownload } from "/@/utils/download";

const emit = defineEmits(["emitSubmit"]);

const props = defineProps({
  years: Array
});

const state = reactive({
  yearList: props.years, // ["2022", "2021", "2020"]
  formData: {
    year: (props.years && props.years[0]) || ""
  }
});
const handleCancel = () => {
  emit("emitSubmit");
};
const handleSubmit = async () => {
  await postDownload(
    `/rdms-admin/fee/summary/statistics/export/${state.formData.year}`,
    `科研经费合计导出.xlsx`
  );
};
</script>
